package com.yanfan.modbus.frame;

import com.yanfan.modbus.code.FunctionCode;
import com.yanfan.modbus.exception.ModbusTransportException;
import com.yanfan.modbus.frame.abs.ModbusResponse;
import io.netty.buffer.ByteBuf;


public class WriteMaskRegisterResponse extends ModbusResponse {
    private int writeOffset;
    private int andMask;
    private int orMask;


    public WriteMaskRegisterResponse(int slaveId) throws ModbusTransportException {
        super(slaveId);
    }

    public WriteMaskRegisterResponse(int slaveId, int writeOffset, int andMask, int orMask) throws ModbusTransportException {
        super(slaveId);
        this.writeOffset = writeOffset;
        this.andMask = andMask;
        this.orMask = orMask;
    }


    @Override
    public byte getFunctionCode() {
        return FunctionCode.WRITE_MASK_REGISTER;
    }


    @Override
    protected void writeResponse(ByteBuf queue) {
        queue.writeShort(writeOffset);
        queue.writeShort(andMask);
        queue.writeShort(orMask);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void readResponse(ByteBuf queue) {
        writeOffset = queue.readUnsignedShort();
        andMask = queue.readUnsignedShort();
        orMask = queue.readUnsignedShort();
    }


    public int getWriteOffset() {
        return writeOffset;
    }


    public int getAndMask() {
        return andMask;
    }


    public int getOrMask() {
        return orMask;
    }
}
